//
//  CCDChooseButtonTableView.m
//  operativeSide
//
//  Created by 王春程 on 16/5/18.
//  Copyright © 2016年 com.caocaod.www. All rights reserved.
//

#import "CCDChooseButtonTableView.h"
#import "CCDChooseButtonCell.h"
@interface CCDChooseButtonTableView ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic)               NSArray *nameArr;

@end
@implementation CCDChooseButtonTableView
static NSString *identifier = @"chooseButtonCell";

- (NSArray *)nameArr {
    if(!_nameArr) {
        _nameArr = @[@"收派员",@"集结点",@"支线",@"BD",@"历史订单",@"个人资料",@"扫一扫",@"转运"];
    }
    return _nameArr;
}

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    if(self = [super initWithFrame:frame style:style]) {
        [self registerClass:[CCDChooseButtonCell class] forCellReuseIdentifier:identifier];
        self.dataSource = self;
        self.delegate = self;
        self.scrollEnabled = YES;
        [self setBounces:NO];
        self.backgroundColor = [UIColor whiteColor];
        [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        
    }
    return self;
}

#pragma mark - UITableViewD
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSInteger index;
    NSString *nameString = self.dataArr[indexPath.row];
    
    for(NSInteger i = 0 ; i < self.nameArr.count ; i ++) {
        if([nameString isEqualToString:self.nameArr[i]]) {
            index = i;
        }
    }
    
    NSString *conString = UserValue(@"controllerMessage");
    if([conString isEqualToString:@"HomeCon"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"homeChooseMessage"
                                                            object:[NSString
                                                                    stringWithFormat:@"%ld",index]];
    } else if([conString isEqualToString:@"HomeSendCon"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"chooseMessage"
                                                            object:[NSString
                                                                    stringWithFormat:@"%ld",index]];
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"login"
                                                        object:nameString];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 25;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CCDChooseButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    NSString *nameString = self.dataArr[indexPath.row];
    cell.titleLabel.text = nameString;
    return cell;
}

@end
